﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Guline.Web.XjsGame.Controllers
{
    public class PlayController : BaseController
    {
        //
        // GET: /Play/
        [Authorize]
        public ActionResult Index()
        {
           
            string username = User.Identity.Name;
            int time = UnixTimeStampUTC();
            //md5($user.'xianlingkey'.$time);
            string sid = FormsAuthentication.HashPasswordForStoringInConfigFile(username + "xianlingkey"+time, "md5");

            int serverid = 1;
            var sv = db.servers.Where(m => m.id == serverid).FirstOrDefault();
            string baomat = FormsAuthentication.HashPasswordForStoringInConfigFile(username + "baomatgame" + time, "md5");

            var account = db.accounts.Where(m => m.name == username).FirstOrDefault();
            account.lastserverid = serverid;
            account.lastnameserver = sv.servername;
            account.baomat = baomat.ToLower();
            db.SaveChanges();

            string url = "http://124.158.10.238/index.php?serverid=" + serverid + "&username=" + username + "&ip=" + sv.gameipdx + "&time=" + time + "&sid=" + sid.ToLower() + "&port=" + baomat.ToLower() + "&game=" + sv.gameipdx;
            
            Models.GamePlay gp = new Models.GamePlay();
            gp.Url = url;
            gp.ServerID = serverid;
            gp.Username = username;
            return View(gp);
        }

    }
}
